package com.yfux.springbootparam.controller;

import com.yfux.springbootparam.pojo.Emp;
import com.yfux.springbootparam.util.XmlParserUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class EmpController {

    @RequestMapping("/listEmp")
    public List<Emp> list() {
        String file = getClass().getClassLoader().getResource("emp.xml").getFile();
        List<Emp> empList = XmlParserUtils.parse(file, Emp.class);
        empList.stream().forEach(emp -> {
            String gender = emp.getGender();
            switch (gender) {
                case "1":
                    emp.setGender("男");
                case "2":
                    emp.setGender("女");
            }

            String job = emp.getJob();
            switch (job) {
                case "1":
                    emp.setJob("讲师");
                case "2":
                    emp.setJob("班主任");
                case "3":
                    emp.setJob("就业指导");
            }
        });
        return empList;
    }
}
